﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using Medianamik.UI.Lock;
using NLog;
using Medianamik.Core;
using Medianamik.Core.Logging;
using Medianamik.Core.Sugar;
using System.Globalization;
using Medianamik.UI.Controls;
using Telerik.Web.UI;
using System.Collections;

namespace Medianamik.UI.Services
{
    [WebService(Namespace = "http://absolunet.com/medianamik/webservices/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    [System.Web.Script.Services.ScriptService]
    public class ContentManager : System.Web.Services.WebService
    {
        [WebMethod]
        public RadTreeNodeData[] GetChildNodesForTreeView(RadTreeNodeData node, IDictionary context)
        {
            List<Node> nodes = NodeManager.GetChildNodes(new Guid(node.Value), false, 1);

            bool? skipUnnamed = context["SkipUnnamed"] as bool?;

            if(skipUnnamed.GetValueOrDefault(true))
                nodes.RemoveAll(n => String.IsNullOrEmpty(n.Name));

            nodes.Sort((n1, n2) => n1.LongPosition.CompareTo(n2.LongPosition));

            return nodes.Select(n => n.ToRadTreeNodeData<Node>((string)context["CultureName"]))
                .ToArray();
        }
    }
}
